package com.server.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.server.pojo.base.PojoBase;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.Hibernate;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Getter
@Setter
@ToString

@Entity
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Table
public class AlarmMessage  extends PojoBase {


    String content;

    String paths = "";

    @ManyToOne
    MobileApp mobileApp;

    @ManyToOne
    @JsonIgnore
    @ToString.Exclude
    Alarm alarm;

    public AlarmMessage setPaths(List<String> paths) {
        this.paths = String.join(",", paths);
        return this;
    }

    public List<String> getPaths() {
        return Arrays.asList(paths.split(","));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        AlarmMessage that = (AlarmMessage) o;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
